<link href="<?php echo ThemePath(); ?>/css/bootstrap-multiselect.css" rel="stylesheet" type="text/css">
<script src="<?php echo ThemePath(); ?>/js/bootstrap-multiselect.js" type="text/javascript"></script>
<div class="span12">
    <ul class="breadcrumb">
        <li class="previous"><a href="<?php echo SITE_URL; ?>">Home</a> /</li>
        <li><a href="javascript:void(0)">Class <?php echo (!$model->isNewRecord) ? 'Update' : 'Create'; ?></a></li>
    </ul>
    <div class="common">
        <div class="whiteBg blueBor padding20px">
            <h5 class="fnt-size20">Create A Class</h5>
        </div>
    </div>
    <div class="common">
        <?php $form = $this->beginWidget('GxActiveForm', array('id' => 'classes-form',)); ?>
        <fieldset>
            <div class="createBox addmarginB20">
                <h4 class="txtfff fnt-size20"><span class="stepCount">Step 1</span>Class Information</h4>
                <div class="padding20px">
                    <div class="formElements">
                        <div class="col-3">
                            <div class="common">
                                <?php echo $form->labelEx($model, 'class_titile'); ?>
                                <div class="clear"></div>
                                <?php echo $form->textField($model, 'class_titile', array('maxlength' => 145, 'class' => 'field oneCol')); ?>
                                <?php echo $form->error($model, 'class_titile'); ?>
                                <div class="clear"></div>
                            </div>

                            <div class="common">
                                <div class="col col1">
                                    <?php echo $form->labelEx($model, 'category_id'); ?>
                                    <div class="clear"></div>
                                    <?php echo $form->dropDownList($model, 'category_id', CHtml::listData(Category::model()->findAll(array('condition' => 'status = ' . SkillConfig::STATUS_ACTIVE, 'order' => 'name ASC')), 'id', 'name'), array('empty' => 'Select Category', 'class' => 'fancySelectBox')); ?>
                                    <?php echo $form->error($model, 'category_id'); ?>
                                </div>

                                <div class="col col2">
                                    <?php echo $form->labelEx($model, 'difficulty_type'); ?>
                                    <div class="clear"></div>
                                    <?php echo $form->dropDownList($model, 'difficulty_type', array("1" => "Beginner", "2" => "Intermediate", "3" => "Advance"), array('class' => 'fancySelectBox')); ?>
                                    <?php echo $form->error($model, 'difficulty_type'); ?>
                                </div>

                                <div class="col col3">
                                    <?php echo $form->labelEx($model, 'classesTargetAudiences'); ?>
                                    <em class="sprite question-sign" title="<?php echo Message::Target_Audiences; ?>">&nbsp;</em><div class="clear"></div>
                                    <?php echo $form->dropDownList($model, 'classesTargetAudiences', CHtml::listData(TargetAudience::model()->findAll(array('condition' => 'status = ' . SkillConfig::STATUS_ACTIVE, 'order' => 'target_audience_name ASC')), 'id', 'target_audience_name'), array('class' => 'multiselect', 'multiple' => 'multiple', 'options' => getAllTargetAudience($model->id, 'class'))); ?>
                                    <?php echo $form->error($model, 'classesTargetAudiences'); ?>
                                </div>

                                <div class="clear"></div>

                            </div>

                            <div class="common">
                                <div class="col col1 ">
                                    <?php echo $form->labelEx($model, 'Suggest Class Tags'); ?>
                                    <em class="sprite question-sign" title="<?php echo Message::SUGGEST_TAG; ?>">&nbsp;</em>
                                    <div class="clear"></div>
                                    <input maxlength="100" name="ClassCourseTags[tag_name]" id="ClassCourseTags_tag_name" type="text" class="field  classTag">
                                    <?php #echo $form->textField($model, 'class_tag', array('class' => 'field oneCol classTag', 'title' => 'class tag', 'onkeyup' => 'commaSepratedValue("Classes_class_tag","limit")')); ?>
                                </div>

                                <div class="col col3">
                                    <?php echo $form->labelEx($model, 'class_tag'); ?>
                                    <em class="sprite question-sign" title="<?php echo Message::CLASSES_TAG; ?>">&nbsp;</em>
                                    <div class="clear"></div>
                                    <?php echo $form->dropDownList($model, 'class_tag', CHtml::listData(ClassCourseTags::model()->findAll(array('condition' => 'status = ' . SkillConfig::STATUS_ACTIVE, 'order' => 'id ASC')), 'id', 'tag_name'), array('class' => 'multiselect', 'multiple' => 'multiple', 'options' => getAllTags($model->id, 'class'))); ?>
                                    <?php echo $form->error($model, 'class_tag'); ?>
                                </div>


                                <div class="clear"></div>
                            </div>





                            <div class="common">
                                <div class="col col1">
                                    <label>Fun Quotient</label><em class="sprite question-sign" title="<?php echo Message::CLASSES_FUN; ?>">&nbsp;</em>
                                     <input type="text" readonly="readony"id="funlearing" value=" <?php echo $modelFunLearning->fun; ?>" name="FunLearningValue[fun]" style="font-weight: bold;background: #fff;cursor: none;padding: 0px;border:0; color:#000; font-weight:bold;"><div class="clear"></div>
                                    <div class="rating ">
                                        <?php /*
                                          $this->widget('CStarRating', array(
                                          'name' => 'FunLearning[fun]',
                                          'minRating' => 0.5,
                                          'ratingStepSize' => 0.5,
                                          'maxRating' => 5,
                                          'value' => $modelFunLearning->fun,
                                          'callback' => 'function(){
                                          $.ajax({
                                          type: "POST",
                                          url: "' . Yii::app()->createUrl('Classes/starRatingAjax') . '",
                                          data: "' . Yii::app()->request->csrfTokenName . '=' . Yii::app()->request->getCsrfToken() . '&rate=" + $(this).val(),
                                          success: function(msg){
                                          var temp=$("#tempfun").val(msg);
                                          var learnTemp= $("#templearn").val();
                                          getFunLearn(msg,learnTemp,"fun");
                                          }})}'
                                          ));
                                         */ ?> 
                                    </div>
                                </div>

                                <div class="col col2">
                                    <label>Learn Quotient</label> <em class="sprite question-sign" title="<?php echo Message::CLASSES_LEARN; ?>">&nbsp;</em>
                                    <input type="text" readonly="readony" id="learingfun" value=" <?php echo $modelFunLearning->learn; ?>" name="FunLearningValue[learn]" style="font-weight: bold;background: #fff;cursor: none;padding: 0px;border:0; color:#000; font-weight:bold;">
                                    <div class="clear"></div>                                
                                    <div class="rating "> 
                                        <?php /*
                                          $this->widget('CStarRating', array(
                                          'name' => 'FunLearning[learn]',
                                          'minRating' => 0.5,
                                          'ratingStepSize' => 0.5,
                                          'value' => $modelFunLearning->learn,
                                          'maxRating' => 5,
                                          'callback' => '
                                          function(){
                                          $.ajax({
                                          type: "POST",
                                          url: "' . Yii::app()->createUrl('Classes/starRatingAjax') . '",
                                          data: "' . Yii::app()->request->csrfTokenName . '=' . Yii::app()->request->getCsrfToken() . '&rate=" + $(this).val(),
                                          success: function(msg){
                                          var temp=$("#templearn").val(msg);
                                          var funtemp =$("#tempfun").val();
                                          getFunLearn(funtemp,msg,"learn");}})}'
                                          ));
                                         * <input type="hidden" id="funLearningfun" name="FunLearningValue[fun]" value=" <?php echo$modelFunLearning->fun; ?>">
                                          <input type="hidden" id="funLearninglearn" name="FunLearningValue[learn]" value="<?php echo$modelFunLearning->learn; ?>">
                                          <input type="hidden" id="tempfun" name="tempfun" value=" <?php echo$modelFunLearning->fun; ?>">
                                          <input type="hidden" id="templearn" name="templearn" value="<?php echo$modelFunLearning->learn; ?>"><br/>
                                         */ ?>
                                    </div>
                                </div>
                                <div class="clear"></div>
                                <div class="errorMessage" id="funLearninglearnText"></div>  
                                <div id="slider-range-max" style="width: 64%;"></div>
                            </div>

                            <div class="common">
                                <?php echo $form->labelEx($model, 'class_short_description'); ?><em class="sprite question-sign" title="<?php echo Message::CLASSES_SHORT_DESC; ?>">&nbsp;</em>
                                <div class="clear"></div>
                                <?php echo $form->textArea($model, 'class_short_description', array('onkeyup' => 'countChar(this);', 'class' => ' requiredfield', 'id' => 'class_short_description')); ?>

                                <div id="charNum" class="errorMessage"></div>
                                <?php echo $form->error($model, 'class_short_description'); ?>
                                <div class="clear"></div>
                            </div>

                            <div class="common">
                                <?php echo $form->labelEx($model, 'class_description'); ?> <em class="sprite question-sign" title="<?php echo Message::CLASSES_DESC; ?>">&nbsp;</em>
                                <div class="clear"></div>
                                <?php
                                $this->widget('common.extensions.ckeditor.CKEditor', array(
                                    'model' => $model,
                                    'attribute' => 'class_description',
                                    'editorTemplate' => 'full',
                                ));
                                ?>

                                <?php echo $form->error($model, 'class_description'); ?>
                                <div class="clear"></div>
                            </div>

                            <div class="common">
                                <?php echo $form->labelEx($model, 'class_outcome'); ?> <em class="sprite question-sign" title="<?php echo Message::CLASSES_OUTCOME; ?>">&nbsp;</em>
                                <div class="clear"></div>
                                <?php
                                $this->widget('common.extensions.ckeditor.CKEditor', array(
                                    'model' => $model,
                                    'attribute' => 'class_outcome',
                                    'editorTemplate' => 'full',
                                ));
                                ?>
                                <?php echo $form->error($model, 'class_outcome'); ?>
                                <div class="clear"></div>
                            </div>

                            <div class="common">
                                <?php echo $form->labelEx($model, 'class_prerequisites'); ?> <em class="sprite question-sign" title="<?php echo Message::CLASSES_PREREQUISITES; ?>">&nbsp;</em>
                                <div class="clear"></div>
                                <?php
                                $this->widget('common.extensions.ckeditor.CKEditor', array(
                                    'model' => $model,
                                    'attribute' => 'class_prerequisites',
                                    'editorTemplate' => 'full',
                                ));
                                ?>
                                <?php echo $form->error($model, 'class_prerequisites'); ?>
                                <div class="clear"></div>
                            </div>

                            <div class="common">
                                <div class="col col1">
                                    <?php echo $form->labelEx($model, 'certificate'); ?>
                                    <div class="clear"></div>
                                    <?php echo $form->dropDownList($model, 'certificate', array("0" => "No", "1" => "Yes"), array('class' => 'fancySelectBox')); ?>
                                    <?php echo $form->error($model, 'certificate'); ?>
                                </div>                                           
                                <div class="clear"></div>
                            </div>
                        </div>
                    </div>                   
                </div> 
            </div>
            <div class="common">
                <p class="alignR"><?php echo GxHtml::submitButton(Yii::t('app', 'Save & Continue'), array('class' => 'btn')); ?></p>
            </div>
        </fieldset>

        <?php $this->endWidget(); ?></div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        $(".dynamicclass").removeAttr('id');
        var orderCount = 0;
        $('.multiselect').multiselect({
            buttonText: function(options) {
                if (options.length == 0) {
                    return 'None selected ';
                }
                else if (options.length > 2) {
                    return options.length + ' selected  ';
                }
                else {
                    var selected = [];
                    options.each(function() {
                        selected.push([$(this).text(), $(this).data('order')]);
                    });

                    selected.sort(function(a, b) {
                        return a[1] - b[1];
                    })

                    var text = '';
                    for (var i = 0; i < selected.length; i++) {
                        text += selected[i][0] + ', ';
                    }

                    return text.substr(0, text.length - 2) + ' ';
                }
            },
            onChange: function(option, checked) {
                if (checked) {
                    orderCount++;
                    $(option).data('order', orderCount);
                }
                else {
                    $(option).data('order', '');
                }
            }
        });


    });

    $(function() {
        $( "#slider-range-max" ).slider({
            range: "max",
            min: 0,
            max: <?php echo SkillConfig::FUN_LEARING_LIMIT; ?>,
            step: 10,
            value: <?php echo (!$model->isNewRecord) ? $modelFunLearning->fun : 30; ?>,
            slide: function( event, ui ) {
                $( "#funlearing" ).val( ui.value );
                $("#learingfun").val(100-ui.value);
            }
        });
        $( "#funlearing" ).val( $( "#slider-range-max" ).slider( "value" ) );
        $( "#learingfun" ).val(100- $( "#slider-range-max" ).slider( "value" ) );
    });
</script>

